home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX2_9.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  3KB  |  67 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/Gen_String.h>            // Include Gen_String header file
  14. #include <cool/Regexp.h>            // Include Regexp header file
  15.  
  16. int main (void) {
  17.   CoolGen_String s1 = "Hello";            // Create string object
  18.   cout << "s1 reads: " << s1 << "\n";        // Display string value
  19.   cout << "s1 has " << strlen (s1) << " characters\n"; // Display char count
  20.   s1 = s1 + " " + "world!";            // Concatenate characters
  21.   cout << "s1 reads: " << s1 << "\n";        // Display string value
  22.   cout << "s1 has " << strlen (s1) << " characters\n"; // Display char count
  23.   s1.reverse ();                // Reverse character order
  24.   cout << "s1 backwards reads: " << s1 << "\n";    // Output reversed string
  25.   s1.reverse ();                // Get normal ordering back
  26.   cout << "s1 upper case: " << upcase (s1) << "\n"; // Display uppercase value
  27.   cout << "s1 lower case: " << downcase (s1) << "\n";// Display downcase value
  28.   cout << "s1 capitalized: " << capitalize (s1) << "\n"; // Display capitalized value
  29.   s1.insert ("Oh, ", 0);            // Insert at start of string
  30.   cout << "s1 reads: " << s1 << "\n";        // Display string value
  31.   s1.replace ("Goodbye", 4, 9);            // Replace `hello' with `goodbye'
  32.   cout << "s1 reads: " << s1 << "\n";        // Display string value
  33.   s1.remove (4, 12);                // Remove `goodbye'
  34.   cout << "s1 reads: " << s1 << "\n";        // Display string value
  35.   s1.compile("Hi There");            // Define simple pattern
  36.   s1 = "Garbage Hi There garbage";        // Set string to search
  37.   cout << "The pattern `Hi There' ";        // Output start of sentence
  38.   if (s1.find () == TRUE)                // Pattern found in string?
  39.     cout << "is";                // Yes, indicate afirmative
  40.   else
  41.     cout << "is not";                // Else indicate failure
  42.   cout << " found in `" << s1 << "'\n";        // And complete output
  43.   cout << "The pattern begins at zero-relative index " << s1.start ();
  44.   cout << " and ends at index " << s1.end () << "\n";
  45.   s1.compile("[^ab1-9]");            // Complex pattern
  46.   s1 = "ab123QQ59ba";                // Another string to search
  47.   cout << "The pattern `[^ab1-9]' ";        // Output start of sentence
  48.   if (s1.find () == TRUE)                // Pattern found in string?
  49.     cout << "is";                // Yes, indicate afirmative
  50.   else
  51.     cout << "is not";                // Else indicate failure
  52.   cout << " found in `" << s1 << "'\n";        // And complete output
  53.   cout << "The pattern begins at zero-relative index " << s1.start ();
  54.   cout << " and ends at index " << s1.end () << "\n";
  55.   s1.compile("O(.*r)");                // New complex pattern
  56.   s1 = "That's OK for me. OK for you?";        // Another string to search
  57.   cout << "The pattern `O(.*r)' ";        // Output start of sentence
  58.   if (s1.find () == TRUE)                // Pattern found in string?
  59.     cout << "is";                // Yes, indicate afirmative
  60.   else
  61.     cout << "is not";                // Else indicate failure
  62.   cout << " found in `" << s1 << "'\n";    // And complete output
  63.   cout << "The pattern begins at zero-relative index " << s1.start ();
  64.   cout << " and ends at index " << s1.end () << "\n";
  65.   return (0);                    // Exit with OK status
  66. }
  67.